package cn.hl.hm.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.hl.hm.entity.TFeedbackEntity;
import cn.hl.hm.entity.TReviewsEntity;
import cn.hl.hm.service.TFeedbackService;
import cn.hl.hm.util.InfoCode;
import cn.hl.hm.util.JacksonJsonUtil;
import cn.hl.hm.util.Result;


@Controller
@RequestMapping("/oldFeedbackController")
public class TFeedbackController {
	private static Logger logger = Logger.getLogger(TFeedbackController.class);
	@Autowired
	private TFeedbackService tFeedbackService; 

	//提交反馈
	@RequestMapping(value = "/feedback", method = RequestMethod.POST)
    public
    @ResponseBody
    String feedback(
    		@RequestParam("userId") Integer userId,//userId
    		@RequestParam("appId") Integer appId,//应用ID
    		@RequestParam("source") Integer source,//1普通用户 2司机
    		@RequestParam("apiVersion") Integer apiVersion,//api版本号
    		@RequestParam("feedbackContent") String feedbackContent,//内容
    		@RequestParam("feedbackType") Integer feedbackType,//反馈来源类型  网站 1 、iOS2 App 3
    		HttpServletRequest request, HttpServletResponse response) {
      try{   
    	  logger.info("提交反馈:"+"source"+source+"userId"+userId+"appId"+appId+"apiVersion"+apiVersion+"feedbackContent"+feedbackContent);
    	  if(null == source || "null".equals(source)||null == feedbackType || "null".equals(feedbackType)|| null == userId || "null".equals(userId) || null == appId || "null".equals(appId) || null == apiVersion || "null".equals(apiVersion)|| null == feedbackContent || "null".equals(feedbackContent)){
    			Result.ok(null, InfoCode.FAILURE, response);
 		 }
    	  TFeedbackEntity i=null;
    	  Map<String,String>map=new HashMap<>();
    	   map.put("source", source+"");
    	   map.put("userId", userId+"");
    	   map.put("appId", appId+"");
    	   map.put("apiVersion", apiVersion+"");
    	   map.put("feedbackContent", feedbackContent);
    	   map.put("feedbackType", feedbackType+"");
    	  i= tFeedbackService.insert(map);
    	  if(i !=null && !("null".equals(i))){
    			Result.ok(i, InfoCode.SUCCESS, response);
    	  }else{
    		  Result.ok(i, InfoCode.FAILURE, response);
    	  }
      }catch(Exception e){
    	  Result.ok(null, InfoCode.FAILURE, response);
    	  e.printStackTrace();
    	  logger.error("feedback方法中抛出异常"+e);
      }
	
 return null;
	}
	//查看意见反馈列表
	@RequestMapping(value = "/feedbackList", method = RequestMethod.POST)
	 public
	    @ResponseBody
	    String feedbackList(
	    		@RequestParam("userId") Integer userId,
	    		@RequestParam("pageId") String limitString,//请求此Id以后的数据，如果为0则请求最新
	    		@RequestParam("pageCount") String pageSizeString,//请求数量
	    		@RequestParam("source") Integer source,//1普通用户 2司机
	    		HttpServletRequest request, HttpServletResponse response) {
			    List<TFeedbackEntity> ttteList=new ArrayList<>();
			    Map<String,Object>map2=null;
	      try{    
	    	  logger.info("查看意见反馈列表列表:"+"source"+source+"userId"+userId+"pageId"+limitString+"pageCount"+pageSizeString);
	    	  if(source ==null || "null".equals(source) ||userId ==null || "null".equals(userId) ||limitString ==null || "null".equals(limitString)||pageSizeString ==null || "null".equals(pageSizeString)){
	    	      Result.ok(map2, InfoCode.FAILURE, response);
	               }
	              Map<String,String>map=new HashMap<>();
	              if(limitString !=null && limitString !="" && !("null".equals(limitString))){
	            	 map.put("pageId", limitString);
	              }
	              if(pageSizeString !=null && pageSizeString !="" && !("null".equals(pageSizeString))){
	            	  map.put("pageCount", pageSizeString);
	               }
	              if(userId !=null && !("null".equals(userId))){
	            	  map.put("userId", userId+"");
	               }
	              if(source !=null && !("null".equals(source))){
	            	  map.put("source", source+"");
	               }
	              logger.info(JacksonJsonUtil.beanToJson(map));
	    		  ttteList= tFeedbackService.getTFeedbackList(map);
	    		  map2=new HashMap<>();
	    		  map2.put("feedbackList", ttteList);
	    		  Result.ok(map2, InfoCode.SUCCESS, response);
	      }catch(Exception e){
	    	  Result.ok(map2, InfoCode.FAILURE, response);
	    	  e.printStackTrace();
	    	  logger.error("feedbackList方法中抛出异常"+e);
	      }
		
	 return null;
		}
   //查看司机评论列表
	@RequestMapping(value = "/driverReviewList", method = RequestMethod.POST)
	 public
	    @ResponseBody
	    String driverReviewList(
	    		@RequestParam("userId") Integer userId,
	    		@RequestParam("pageId") String limitString,//请求此Id以后的数据，如果为0则请求最新
	    		@RequestParam("pageCount") String pageSizeString,//请求数量
	    		@RequestParam("source") Integer source,//1普通用户 2司机
	    		HttpServletRequest request, HttpServletResponse response) {
			  List<TReviewsEntity> ttteList=new ArrayList<>();
			    Map<String,Object>map2=null;
	      try{    
	    	  logger.info("查看司机评论列表:"+"source"+source+"userId"+userId+"pageId"+limitString+"pageCount"+pageSizeString);
	    	  if(source ==null || "null".equals(source) ||userId ==null || "null".equals(userId) ||limitString ==null || "null".equals(limitString)||pageSizeString ==null || "null".equals(pageSizeString)){
	    		  Result.ok(map2, InfoCode.FAILURE, response);
	               }
	              Map<String,String>map=new HashMap<>();
	              if(limitString !=null && limitString !="" && !("null".equals(limitString))){
	            	 map.put("pageId", limitString);
	              }
	              if(pageSizeString !=null && pageSizeString !="" && !("null".equals(pageSizeString))){
	            	  map.put("pageCount", pageSizeString);
	               }
	              if(userId !=null && !("null".equals(userId))){
	            	  map.put("userId", userId+"");
	               }
	              if(source !=null && !("null".equals(source))){
	            	  map.put("source", source+"");
	               }
	              logger.info(JacksonJsonUtil.beanToJson(map));
	    		  ttteList= tFeedbackService.selectDriverReviewList(map);
	    		  map2=new HashMap<>();
	    		  map2.put("review", ttteList);
	    		  Result.ok(map2, InfoCode.SUCCESS, response);
	      }catch(Exception e){
	    	  Result.ok(map2, InfoCode.FAILURE, response);
	    	  e.printStackTrace();
	    	  logger.error("driverReviewList查看司机评论列表方法中抛出异常"+e);
	      }
		
	 return null;
		}
}
